<?php
class ModulePrivilegeRoleVo extends SzAbstractMySqlVo
{

    private $roleId;
    private $userId;
    private $name;
    private $status;
    private $privilegeIds;

    /**
     * Initialize ModulePrivilegeRoleVo.
     *
     * @param $roleId
     * @param $userId
     * @param $name
     * @param $status
     * @param $privilegeIds
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ModulePrivilegeRoleVo
     */
    public function __construct($roleId, $userId, $name, $status, $privilegeIds, $isInsert = false) {
        $this->roleId = $roleId;
        $this->userId = $userId;
        $this->name = $name;
        $this->status = $status;
        $this->privilegeIds = json_decode($privilegeIds, true);

        $this->isInsert = $isInsert;
        $this->voClassName = 'ModulePrivilegeRoleVo';
        $this->ormName = 'ModulePrivilegeRole';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'roleId' => $this->getRoleId(),
            'userId' => $this->getUserId(),
            'name' => $this->getName(),
            'status' => $this->getStatus(),
            'privilegeIds' => ($needEncode) ? $this->getPrivilegeIds() : $this->getRawPrivilegeIds(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'roleId' => $this->getRoleId(),
            'userId' => $this->getUserId(),
            'name' => $this->getName(),
            'status' => $this->getStatus(),
            'privilegeIds' => ($needEncode) ? $this->getPrivilegeIds() : $this->getRawPrivilegeIds(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getRoleId(),
            $this->getUserId(),
            $this->getName(),
            $this->getStatus(),
            $this->getPrivilegeIds(),
        );
    }

    public function getRoleId()
    {
        return $this->roleId;
    }

    public function setRoleId($val)
    {
        $this->saveColumnStatus(0, $this->roleId);
        $this->roleId = $val;
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(1, $this->userId);
        $this->userId = $val;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($val)
    {
        $this->saveColumnStatus(2, $this->name);
        $this->name = $val;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($val)
    {
        $this->saveColumnStatus(3, $this->status);
        $this->status = $val;
    }

    public function getPrivilegeIds()
    {
        return json_encode($this->privilegeIds);
    }

    public function getRawPrivilegeIds()
    {
        return $this->privilegeIds;
    }

    public function setPrivilegeIds($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 65535) {
            SzLogger::get()->error('[ModulePrivilegeRoleVo] The length of column privilegeIds exceed the limit, length / limit: ' . $encodedLength . ' / 65535');
            throw new SzException(10522, array('ModulePrivilegeRoleVo', '65535', $encodedLength));
        } else if ($encodedLength > 58981) {
            SzLogger::get()->warn('[ModulePrivilegeRoleVo] The length of column privilegeIds exceed the warning level, length / limit: ' . $encodedLength . ' / 65535');
        }
        $this->saveColumnStatus(4, $this->privilegeIds);
        $this->privilegeIds = $val;
    }

}